package com.ruoyi.project.drug.controller;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.drug.domain.DrugOrderCustom;
import com.ruoyi.project.drug.domain.DrugOrderDetail;
import com.ruoyi.project.drug.service.IDrugOrderCustomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Classname DrugOrderCustomController
 * @Description
 * @Date 2022/6/28 23:06
 * @Author Lee
 */
@RestController
@RequestMapping("/drugs/order")
public class DrugOrderCustomController extends BaseController {
    @Autowired
    private IDrugOrderCustomService customService;

    @GetMapping("/list")
    @PreAuthorize("@ss.hasPermi('/drugs:order:list')")
    public TableDataInfo list(DrugOrderCustom orderCustom){
        startPage();
        return getDataTable(customService.selectDrugOrderCustomList(orderCustom));
    }
    /**
     * 新增采购单据
     * @param supportId 供应商主键
     * @param orderTotal 单据总额
     * @param drugOrderDetails 明细集合
     * @return
     */
    @PostMapping("/{supportId}/{orderTotal}")
    public AjaxResult addDrugOrder(@PathVariable Integer supportId, @PathVariable Double orderTotal,
                                   @RequestBody List<DrugOrderDetail> drugOrderDetails){
        return toAjax(customService
                .insertDrugOrderAndDetails(supportId, orderTotal, SecurityUtils.getUsername(), drugOrderDetails));
    }
}
